<?php
include 'konek.php';

session_start();
if(!isset($_SESSION['username']))
   {   
  ?><script language="javascript">alert('anda blm login');
document.location='../'</script><?php 
}
else
{
$username = $_SESSION['username'];
$status = $_SESSION['status'];
}

$id=$_POST['id'];
$judul=mysql_real_escape_string($_POST['judul']);
$kelas=$_POST['kls'];
$kategori=$_POST['mapel'];
$isi=mysql_real_escape_string($_POST['area']);

$save=mysql_query("update posting set judul='$judul', kelas=$kelas, kategori=$kategori, isi ='$isi' where idpost=$id  ") or die(mysql_error());

$numbfile=1;
$files=mysql_query("SELECT * FROM file where id_post=$id");
while ($file=mysql_fetch_assoc($files)) 
{
	$idfile=$file['id_file'];
	$data=$_POST['file'.$numbfile.''];
	$update=mysql_query("UPDATE file set nm_file='$data' where id_file=$idfile");
	$numbfile++;
}

while ($numbfile<=5) 
{
	if(!is_null($_POST['file'.$numbfile.'']))
	{
		$img=$_POST['file'.$numbfile.''];
		$insert=mysql_query("insert into file (id_post,nm_file) values ('$id','$img')");
	}
	$numbfile++;
}



header("location:../pages/list.php");

?>